const express = require('express')
const router = express.Router()
const multer = require('multer');
const path = require('path');


const uploadHandler = require('../router_handler/upload')

const storage = multer.diskStorage({
    destination: (req, file, cb) => {
        cb(null, 'uploads/')
    },
    filename: (req, file, cb) => {
        cb(null, Date.now() + path.extname(file.originalname))
    },
})

// 设置文件大小限制为100MB
const upload = multer({ 
    storage,
    limits: { fileSize: 100 * 1024 * 1024 } // 100MB
});

router.post('/uploadVideo', upload.fields([{ name: 'video', maxCount: 1 }]), uploadHandler.uploadVideo)
router.post('/uploadCover', upload.fields([{ name: 'cover', maxCount: 1 }]), uploadHandler.uploadCover)
router.post('/uploadInfo', uploadHandler.uploadInfo)

module.exports = router